package com.dragon.modules.yuegou.enums;

import javax.annotation.Nullable;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 悦商惠小程序菜单
 * 
 * @author liuwu
 *
 */
public enum MerchantMenu implements IMenu {

	/**
	 * 根节点
	 */
	ROOT(400, "悦购小程序", "root", 0);

	/**
	 * 菜单ID
	 */
	private int id;

	/**
	 * 菜单别名（中文名，展示给用户看的名称）
	 */
	private String alias;

	/**
	 * 菜单路径（菜单标识，并不对应接口路径）
	 */
	private String path;

	/**
	 * 父菜单ID，0表示没有父菜单
	 */
	private int parentId;

	private MerchantMenu(int id, String alias, String path, int parentId) {
		this.id = id;
		this.alias = alias;
		this.path = path;
		this.parentId = parentId;
	}

	@Override
	public int getId() {
		return id;
	}

	@Override
	public String getAlias() {
		return alias;
	}

	@Override
	public String getPath() {
		return path;
	}

	@Override
	public int getParentId() {
		return parentId;
	}

	/**
	 * 根据路径获取菜单
	 * 
	 * @param path 菜单路径（标识）
	 * @return 菜单
	 */
	@Nullable
	public static MerchantMenu from(String path) {
		if (path == null) {
			return null;
		}
		return PATH_MAP.get(path);
	}

	/**
	 * Path Map for Menu
	 */
	private static final Map<String, MerchantMenu> PATH_MAP = Stream.of(MerchantMenu.values())
			.collect(Collectors.toMap(MerchantMenu::getPath, UnaryOperator.identity()));

}
